// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using Microsoft.Extensions.DependencyInjection;

namespace SnapObjects.Expressions
{
    internal class EvaluateExpressionParser : ParserBase, IEvaluateExpressionParser
    {
        private readonly IExpressionVisitor<EvaluateResult> _visitor;

        public EvaluateExpressionParser(IServiceProvider provider) : base(provider)
        {
            _visitor = provider.GetService<IExpressionVisitor<EvaluateResult>>();
        }

        public object Parse(EvaluateParserOptions options)
        {
            var context = this.GetContext(options.Expression);

            return _visitor.Visit(context, options)?.Value;
        }
    }
}
